package net.oschina.archx.spring.test;

import net.oschina.archx.spring.datasource.DBContextHolder;
import net.oschina.archx.spring.entity.User;
import net.oschina.archx.spring.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by Archx on 2015/6/22 0022.
 */
@ContextConfiguration(locations = {"classpath:spring-context.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class MultiDataSourceTset {

    @Autowired
    private UserService usv;


    public void test(){
        long id = usv.insertLocal(new User(0L,"admin",18,"admin@qq.com"));
        System.out.println("id is " + id);
        DBContextHolder.setDbContext("remoteDataSource");
        long rid = usv.insertRemote(new User(0L,"test",19,"test@qq.com"));
        System.out.println("remote insert userid is " + rid);
    }

    @Test
    public void trans() {
        //DBContextHolder.setDbContext("remoteDataSource");
        //long id = usv.insertRemote(new User(0L,"admin1",21,"admin@qq.com"));
        //System.out.println("id is " + id);
        DBContextHolder.setDbContext("localDataSource");
        usv.trans(new User(0L,"test1",29,"test@qq.com"));
    }

}
